package com.example.administrator.myapplication.fragment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.databinding.FragmentFindBinding;
import com.example.administrator.myapplication.find.anchor.fragment.AnchorFragment;
import com.example.administrator.myapplication.find.assortment.AssortmentFragment;
import com.example.administrator.myapplication.find.billboard.fragment.BillboardFragment;
import com.example.administrator.myapplication.find.recommend.RecommendFragment;
import com.example.administrator.myapplication.until.CommentFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class FindFragment extends Fragment {
   private FragmentFindBinding binding;

    public FindFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return DataBindingUtil.inflate(inflater,R.layout.fragment_find, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        aboutTablayout();
    }

    private void aboutTablayout() {
        String[] titles = new String[]{"推荐","分类","榜单","主播"};
        List<Fragment> fragments = new ArrayList<>() ;
        fragments.add(new RecommendFragment());
        fragments.add(new AssortmentFragment());
        fragments.add(new BillboardFragment());
        fragments.add(new AnchorFragment());
        CommentFragmentPagerAdapter  adapter = new CommentFragmentPagerAdapter(getChildFragmentManager(),titles,fragments);
        binding.viewpger.setAdapter(adapter);
        binding.tablayout.setupWithViewPager(binding.viewpger);
        binding.viewpger.setOffscreenPageLimit(4);
    }
}
